<%-- 
    Document   : atualizarUsuario
    Created on : 11/10/2011, 00:56:20
    Author     : Neto
--%>
<%@page import="controller.Controlador"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="model.Usuario, javax.servlet.http.HttpSession"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>ATUALIZAR OS SEUS DADOS</title>
    </head>
    <jsp:include page="topologado.jsp"/>
    <body>

        <jsp:useBean id="usuario" class="model.Usuario" scope="session" />
        <%
                    HttpSession sessao = request.getSession(true);
                    try {
                        Usuario usuario1 = (Usuario) sessao.getAttribute("usuario");
                        if (usuario1.getCpf() == null) {
                            response.sendRedirect("login.jsp");
                        } else {
        %>
        <div id="content">
            <br><br><br><br>
            <form action="atualizarUsuario.jsp?cmd=atualizarUser" method="post">
                <table style="text-align: left; width: 0%;" border="1" bordercolor="cccccc" cellpadding="2" cellspacing="2" align="center">
                    <tbody>



                        <tr>
                            <td style="vertical-align: top; text-align: right;">Nome: </td>
                            <td style="vertical-align: top; text-align: left;"><input type="text" name="nome" value="<%= usuario.getNome().trim()%>"></td>
                        </tr>
                        <tr>
                            <td style="vertical-align: top; text-align: right;">Telefone: </td>
                            <td style="vertical-align: top; text-align: left;"><input type="text" name="telefone" value="<%= usuario.getTelefone().trim()%>"></td>
                        </tr>
                        <tr>
                            <td style="vertical-align: top; text-align: right;">CPF: </td>
                            <td style="vertical-align: top; text-align: left;"><input type="text" name="cpf" value="<%= usuario.getCpf().trim()%>"></td>
                        </tr>
                        <tr>
                            <td style="vertical-align: top; text-align: right;">Email: </td>
                            <td style="vertical-align: top; text-align: left;""><input type="text" name="email" value="<%= usuario.getEmail().trim()%>"></td>
                        </tr>
                        <tr>
                            <td style="vertical-align: top; text-align: right;">Login: </td>
                            <td style="vertical-align: top; text-align: left;"><input type="text" name="login" value="<%= usuario.getLogin().trim()%>"readonly="true"></td>
                        </tr>
                        <tr>
                            <td style="vertical-align: top; text-align: right;">Senha: </td>
                            <td style="vertical-align: top; text-align: left;"><input type="password" name="senha" value="<%= usuario.getSenha().trim()%>"></td>
                        </tr>
                        <tr>
                            <td style="vertical-align: top; text-align: right;">Confirme a Senha: </td>
                            <td style="vertical-align: top; text-align: left;"><input type="password" name="senhaconf" value="<%= usuario.getSenha().trim()%>"></td>
                        </tr>
                        <tr>
                            <td style="vertical-align: top; text-align: right;"><input type="submit" value="Atualizar"></td>
                            <td style="vertical-align: top; text-align: left;"><input type="reset" value="Limpar"></td>
                        </tr>
                    </tbody>
                </table>
                <%
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                response.sendRedirect("login.jsp");
                            }

                %>
            </form><br>
            <%
                String id = request.getParameter("id");
                String nome = request.getParameter("nome");
                String cpf = request.getParameter("cpf");
                String telefone = request.getParameter("telefone");
                String email = request.getParameter("email");
                String login = request.getParameter("login");
                String senha = request.getParameter("senha");
                String senhaconf = request.getParameter("senhaconf");
                String cmd = request.getParameter("cmd");
                boolean test = true;

                if (cmd != null && cmd != "") {
                    if (nome == null || nome == "") {
                        out.print("<font color = red><h4><center>Nome inválido!</h4></center></font>");
                        test = false;
                    }
                    if (cpf == null || cpf == "") {
                        out.print("<font color = red><h4><center>CPF inválido</h4></center></font>");
                        test = false;
                    }
                    if (telefone == null || telefone == "") {
                        out.print("<font color = red><h4><center>Telefone inválido</h4></center></font>");
                        test = false;
                    }
                    if (email == null || email == "") {
                        out.print("<font color = red><h4><center>E-mail inválido</h4></center></font>");
                        test = false;
                    }
                    if (login == null || login == "") {
                        out.print("<font color = red><h4><center>Login inválido<h4><center></font>");
                        test = false;
                    }
                    if (senha == null || senha == "") {
                        out.print("<font color = red><h4><center>Confirmação de senha inválida</h4></center></font>");
                        test = false;
                    }
                    if (!senha.equalsIgnoreCase(senhaconf)) {
                        out.print("<font color = red><h4><center>Confirmação de senha inválida<h4><center></font>");
                        test = false;
                    }
                    if (test == true) {
            %>
        </div>

        <jsp:forward page="controlador" >
            <jsp:param name="cmd" value="<%=cmd%>"/>
            <jsp:param name="id" value="<%=id%>"/>
            <jsp:param name="nome" value="<%=nome%>"/>
            <jsp:param name="cpf" value="<%=cpf%>"/>
            <jsp:param name="telefone" value="<%=telefone%>"/>
            <jsp:param name="email" value="<%=email%>"/>
            <jsp:param name="login" value="<%=login%>"/>
            <jsp:param name="senha" value="<%=senhaconf%>"/>
            <jsp:param name="senhaconf" value="<%=senhaconf%>"/>
        </jsp:forward>

        <%}
                }%>
        <jsp:include page="rodape.jsp"/>

    </body>
</html>
